using Game.Main.Model;
using Game.XH;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class CurtainBItem : BaseItem
	{
		private float lastTouchY;

		private float minY;

		private float maxY;

		private float curY;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			minY = base.transform.Find("MinY").localPosition.y;
			maxY = base.transform.Find("MaxY").localPosition.y;
			Transform trans = base.transform.Find("Mask");
			trans.SetLocalZ(-1E-05f);
			curY = data.modelY;
			if (curY != 0f)
			{
				SetCurY(curY);
			}
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			lastTouchY = touchEventData.curPos.y;
		}

		public override void TouchMove(TouchEventData touchEventData)
		{
			SetCurY(model.localPosition.y + (touchEventData.curPos.y - lastTouchY));
			lastTouchY = touchEventData.curPos.y;
		}

		private void SetCurY(float y)
		{
			curY = y;
			if (curY < minY)
			{
				curY = minY;
			}
			else if (curY > maxY)
			{
				curY = maxY;
			}
			model.SetLocalY(curY);
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["39"] = curY.ToString("F3");
		}
	}
}
